<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增课程章节')" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="row">
        <form class="form-horizontal m" id="form-course-add">
        </form>
        <input id="lessonId" class="form-control" type="hidden"  th:value="${lessonId}">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <div class="form-group">
                        <label class="font-noraml">批量上传视频</label>
                        <div class="file-loading">
                            <input id="fileinput" type="file" name="files" multiple>
                        </div>
                    </div>
                    <hr>
                </div>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script type="text/javascript">
        var prefix = ctx + "lesson/course"

        var vods = [];

        var allowedFileExtensions = ["mp3", "mp4"];
		var dropZoneTitle = "支持mp3,mp4上传";

        $(document).ready(function () {
            $("#fileinput").fileinput({
                'theme': 'explorer-fas',
                'uploadUrl': '/lesson/course/batchUploadMedia',
                overwriteInitial: false,
                'allowedFileExtensions': allowedFileExtensions,
                'dropZoneTitle': dropZoneTitle,
            }).on("fileuploaded", function(e, data, previewiId, index){
                 console.log(data.response.vods[0])
        	     vods.push(data.response.vods[0]);
        	     console.log(JSON.stringify(vods));
            });
        });

        function submitHandler() {
            if (vods && vods.length > 0) {
                var url = prefix + "/batchadd";
                var lessonId = $("#lessonId").val();
                var data = {
                   'lessonId': lessonId,
                   'vods': vods
                }
                var config = {
        	        url: url,
        	        type: "post",
        	        dataType: "json",
        	        data: JSON.stringify(data),
        	        contentType: "application/json",
        	        beforeSend: function () {
        	        	$.modal.loading("正在处理中，请稍后...");
        	        	$.modal.disable();
        	        },
        	        success: function(result) {
        	        	if (typeof callback == "function") {
        	        	    callback(result);
        	        	}
        	        	$.operate.successCallback(result);
        	        }
        	    };
        	    $.ajax(config)

            }else{
                $.modal.alertWarning("尚未上传任何视频");
            }
        }

    </script>
</body>
</html>